﻿using System;
using System.Linq;
using Quickie.Models;
using Quickie.Models.IoC;
using Quickie.Models.Data;
using Quickie.Models.Entities;
using Quickie.Models.ViewModel;
using Quickie.Models.Interfaces;

namespace Quickie.Models.Data
{
    public class CompanyRepository : IRepository<Company>
    {
        private readonly IDataProvider data;

        public CompanyRepository(IDataProvider data)
        {
            this.data = data;
        }

        public IQueryable<Company> GetAll()
        {
            return data.Linq<Company>();
        }

        public Company GetByID(int ID)
        {
            try
            {
                return GetAll().Single(x => x.ID == ID);
            }
            catch (Exception)
            {
                return null;
            }
        }

        public void Save(Company item)
        {
            data.Insert(item);
            data.SubmitChanges();
        }

        public void Delete(Company item)
        {
            data.Delete(item);
        }

        public void SaveChanges()
        {
            data.SubmitChanges();
        }
    }

}
